package com.kasinf.sample.log.controller;

import com.kasinf.framework.common.pojo.CommonResult;
import com.kasinf.framework.log.client.define.ApiAccessLog;
import com.kasinf.sample.log.controller.vo.LoginParam;
import com.mzt.logapi.starter.annotation.LogRecord;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author : Kaiser
 * @Date: 2025/7/1  17:05
 */
@ApiAccessLog
@Tag(name = "示例工程 - 测试接口")
@RestController
@RequestMapping("test")
public class TestController {

    @PostMapping("upload")
    public CommonResult<String> upload(@RequestParam("file") MultipartFile file) {
        // 获取文件名
        String fileName = file.getOriginalFilename();
        System.out.println(fileName);
        return CommonResult.success("上传成功");
    }

    @GetMapping("error")
    @Operation(summary = "GET示例")
    public CommonResult<String> testError(LoginParam param) {
        throw new RuntimeException("测试异常");
    }

    @GetMapping
    @Operation(summary = "GET示例")
    public CommonResult<String> testGet(LoginParam param) {
        return CommonResult.success("测试成功");
    }


    @PostMapping
    @Operation(summary = "POST示例")
    public CommonResult<String> testPost(@RequestBody LoginParam param) {
//        boolean flag = postServ(param);
        return CommonResult.success("测试成功");
    }

//    @LogRecord()
//    private boolean postServ(LoginParam param) {
//        return true;
//    }

    @PutMapping
    @Operation(summary = "PUT示例")
    public CommonResult<String> testPut(@RequestBody LoginParam param) {
        return CommonResult.success("测试成功");
    }

    @DeleteMapping
    @Operation(summary = "DELETE示例")
    public CommonResult<String> testDelete(@RequestBody LoginParam param) {
        return CommonResult.success("测试成功");
    }
}
